import request from "@/api";
import { BaseRet, PageQuery, PageRet, SortParam } from "../response";
import { DesignListConfig } from "./designList";

export default class DesignInstanceApi {
  /**
   * 查询配置
   * @returns
   */
  static async queryConfig(listId: string): Promise<DesignInstanceModel> {
    return await request({
      url: `/designInstance/QueryConfig/${listId}`,
      method: "get",
    });
  }

  /**
   * 查询实例数据
   * @returns
   */
  static async query(data: DesignInstanceQuery): Promise<PageRet<object>> {
    return await request({
      url: `/designInstance/Query`,
      method: "post",
      data: data,
    });
  }

  /**
   * 新增
   * @returns
   */
  static async create(data: DesignInstanceEdit): Promise<BaseRet> {
    return await request({
      url: `/designInstance/create`,
      method: "post",
      data: data,
    });
  }

  /**
   * 修改
   * @returns
   */
  static async update(data: DesignInstanceEdit): Promise<BaseRet> {
    return await request({
      url: `/designInstance/update`,
      method: "put",
      data: data,
    });
  }

  /**
   * 删除
   * @returns
   */
  static async delete(formId: string, id: string): Promise<BaseRet> {
    return await request({
      url: `/designInstance/delete/${formId}/${id}`,
      method: "delete",
    });
  }

  /**
   * 详情
   * @returns
   */
  static async details(formId: string, id: string): Promise<object> {
    return await request({
      url: `/designInstance/details/${formId}/${id}`,
      method: "get",
    });
  }
}

export interface DesignInstanceModel {
  listConfig?: DesignListConfig;
  tableConfig?: string;
  formSetting?: DesignInstanceFormSetting;
}

export interface DesignInstanceFormSetting {
  formConfig?: string;
  formItemList?: string;
  formStyle?: string;
  sourceCode?: string;
}

export interface DesignInstanceQuery extends PageQuery {
  searchString?: string;
  query?: DesignQuerySearch[];
  sorts?: SortParam[];
  listId?: string;
}

export interface DesignQuerySearch {
  fieldName?: string;
  fieldValue?: any;
}

export interface DesignInstanceEdit {
  formId?: string;
  formData?: string;
}
